export default {
	namespaced: true,
	state: () => ({
		host:'',
		version:'',
		safety:{
			top:0,
			bottom:0,
			left:0,
			right:0
		},
		enum:null
	}),
	mutations: {
		setHost(state,val){
			uni.setStorageSync('system_host',val);
			state.host = val;
		},
		setVersion(state,val){
			uni.setStorageSync('system_app_version',val);
			state.version = val;
		},
		setSafety(state,obj){
			state.safety = obj;
		},
		setEnum(state,obj){
			uni.setStorageSync('system_enum',JSON.stringify(obj));
			state.enum = obj;
		}
	},
	actions: {
		
	},
	getters: {
		getHost(state){
			let res = state.host;
			if (!res) {
				let temp = uni.getStorageSync('system_host');
				if (temp) {
					res = temp;
					state.host = res;
				}
			}
			return res;
		},
		getVersion(state){
			let res = state.version;
			if (!res) {
				let temp = uni.getStorageSync('system_app_version');
				if (temp) {
					res = temp;
					state.version = res;
				}
			}
			return res;
		},
		getSafety(state){
			return state.safety
		},
		getEnum(state){
			let res = state.enum;
			if (!res) {
				let temp = uni.getStorageSync('system_enum');
				if (temp) {
					try{
						res = JSON.parse(temp)
						state.enum = res;
					}catch(e){
						//TODO handle the exception
					}
				}
			}
			if (!res) res = {}
			return res;
		}
	}
}